package com.chixing.controller;

import com.chixing.pojo.MyOrder;
import com.chixing.service.CarService;
import com.chixing.util.DateUtil;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;


@Controller
public class CarController {
    @Autowired
    CarService carService;
    @GetMapping("car")
    public ModelAndView getAll(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("car_rental/select_car");
        return modelAndView;
    }
    // 车辆详情
    @GetMapping("car/detail/{carId}")
    public ModelAndView getCarDetail(@PathVariable("carId") Integer carId){
        ServerResponse serverResponse = carService.getCarDetail(carId);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("serverResponse",serverResponse);
        modelAndView.setViewName("car_rental/car_detail");
        return modelAndView;
    }
    // 多条件动态查询
    @GetMapping("car/{carType}/{carBrand}/{minCarDailyPrice}/{maxCarDailyPrice}/{carShiftType}/{carSeatNumber}/{orderBy}/{pageNum}")
    @ResponseBody
    public ServerResponse getCarByContain(@PathVariable("carType") String carType,
                                        @PathVariable("carBrand") String carBrand,
                                          @PathVariable("minCarDailyPrice") Float minCarDailyPrice,
                                          @PathVariable("maxCarDailyPrice") Float maxCarDailyPrice,
                                          @PathVariable("carShiftType") String carShiftType,
                                          @PathVariable("carSeatNumber")  Integer carSeatNumber,
                                          @PathVariable("orderBy")  String orderBy,
                                          @PathVariable("pageNum") Integer pageNum) {

        return carService.getCarByContain(carType,carBrand,minCarDailyPrice,maxCarDailyPrice,carShiftType,carSeatNumber,orderBy,pageNum);
    }
    // 主页四个最热门车型
    @GetMapping("index")
    @ResponseBody
    public ServerResponse getHotCarToIndex(){
        return carService.getHotCarToIndex();
    }

    // 通过 车 查 店铺
    @GetMapping("car/{carId}/store")
    public ModelAndView getCarDetailToStorePage(@PathVariable("carId") Integer carId){
        ServerResponse serverResponse = carService.getCarDetail(carId);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("serverResponse",serverResponse);
        modelAndView.setViewName("car_rental/select_car_two");
        return modelAndView;
    }


   @GetMapping("car/{carId}/store/{storeArea}")
   @ResponseBody
   public ServerResponse getByStoreArea(@PathVariable("carId") Integer carId , @PathVariable("storeArea") String storeArea){

        return carService.getStoreByCarIdAndStoreArea(carId,storeArea);
   }

   @GetMapping("car/ContainAndDate")
   @ResponseBody
   public ServerResponse getCarByContainAndDate(Integer storeId,
                                                Date getCarTime,
                                                String carType,
                                                String carBrand,
                                                Float minCarDailyPrice,
                                                Float maxCarDailyPrice,
                                                String carShiftType,
                                                Integer carSeatNumber,
                                                String orderBy,
                                                Integer pageNum){
        return carService.getCarByContainAndDate(storeId, getCarTime,carType,carBrand,minCarDailyPrice,maxCarDailyPrice,carShiftType,carSeatNumber,orderBy,pageNum);
   }
}